package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.DeviceDto;
import com.zzyl.dto.DevicePageQueryDto;
import com.zzyl.service.IotService;

import com.zzyl.vo.DeviceVo;
import com.zzyl.vo.ProductVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author user
 */
@RestController
@RequestMapping("/iot")
@Slf4j
@Api(tags = "设备管理")
public class IotController {
    @Autowired
    private IotService iotService;

    @PostMapping("/syncProductList")
    @ApiOperation(value = "同步产品列表")
    public ResponseResult getDeviceList() {
        iotService.getDeviceList();
        return ResponseResult.success();
    }

    @GetMapping("/allProduct")
    @ApiOperation(value = "获取所有产品")
    public ResponseResult<List<ProductVo>> getAllProduct() {
        List<ProductVo> productVoList = iotService.getAllProduct();
        return ResponseResult.success(productVoList);
    }

    @PostMapping("/RegisterDevice")
    @ApiOperation(value = "注册设备")
    public ResponseResult RegisterDevice(@RequestBody DeviceDto deviceDto) {
        iotService.RegisterDevice(deviceDto);
        return ResponseResult.success();
    }

    @GetMapping("/pageQueryDevice")
    @ApiOperation(value = "分页查询设备")
    public ResponseResult pageQueryDevice(DevicePageQueryDto devicePage) {
        PageResponse<DeviceVo> deviceDataVoList = iotService.pageQueryDevice(devicePage);
        return ResponseResult.success(deviceDataVoList);
    }

    @PostMapping("/QueryDeviceDetail")
    @ApiOperation(value = "查询设备详情")
    public ResponseResult queryDeviceDetail(@RequestBody DeviceDto deviceDto) {
        DeviceVo deviceVo = iotService.queryDeviceDetail(deviceDto);
        return ResponseResult.success(deviceVo);
    }

    @PostMapping("/QueryDevicePropertyStatus")
    @ApiOperation(value = "查询设备属性状态")
    public ResponseResult queryDevicePropertyStatus(@RequestBody DeviceDto deviceDto) {
        return iotService.queryDevicePropertyStatus(deviceDto);
    }

    @PostMapping("/QueryThingModelPublished")
    @ApiOperation(value = "查询物模型发布状态")
    public ResponseResult queryThingModelPublished(@RequestBody DeviceDto deviceDto) {
        return iotService.queryThingModelPublished(deviceDto);
    }

    @PostMapping("/UpdateDevice")
    @ApiOperation(value = "更新备注名称")
    public ResponseResult UpdateDevice(@RequestBody DeviceDto deviceDto) {
        iotService.updateDeviceNikeName(deviceDto);
        return ResponseResult.success();
    }


    @DeleteMapping("/DeleteDevice")
    @ApiOperation(value = "删除设备")
    public ResponseResult deleteDevice(@RequestBody DeviceDto deviceDto) {
        iotService.deleteByIotId(deviceDto);
        return ResponseResult.success();
    }


}
